/*********************************************************************
 * Software License Agreement
 *
 * Copyright (C) 2010 Cross The Road Electronics.  All rights
 * reserved.
 *
 * Cross The Road Electronics (CTRE) licenses to you the right to 
 * use, copy, modify, merge, publish, distribute, sublicense, and/or 
 * sell copies of the Software ONLY when in use with CTRE's 2CAN 
 * Ethernet CAN Gateway.
 *
 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * CROSS THE ROAD ELECTRONICS BE LIABLE FOR ANY INCIDENTAL, SPECIAL, 
 * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
 *
********************************************************************/
#ifndef _2CAN_DLL_API__h_
#define _2CAN_DLL_API__h_

#include "../Common/Os Abstraction/stdint.h"
#include "../Common/2CANClientDefs.h"

//********************************* 2CAN Base API *********************************//
typedef enum _ctr_error_t
{
	ctr_ok,
	ctr_fail,
	ctr_not_implemented,
	ctr_bad_handle,
	ctr_badNodeType,
	ctr_badParameter,
	ctr_nodeNotFound,
}ctr_error_t;

typedef enum _ctr_nodeType_t
{
	ctr_Jaguar,
	ctr_RCM,
	ctr_Gyro,
}ctr_nodeType_t;

ctr_error_t _stdcall CTR_Find2CAN(Found2Can * found2can,uint32_t options);
ctr_error_t _stdcall CTR_Init(const char * ip,uint32_t * handle);
ctr_error_t _stdcall CTR_SetActiveRcmNodeId(uint32_t handle,int nodeId);
ctr_error_t _stdcall CTR_SetCommPeriod(uint32_t handle,uint32_t iPeriod);
ctr_error_t _stdcall CTR_Close(uint32_t handle);
ctr_error_t _stdcall CTR_Enable(uint32_t handle,EnableState enableState,uint64_t outputEnableBits);
ctr_error_t _stdcall CTR_IsEnabled(uint32_t handle,uint32_t * isenabled);

//********************************* Node API *********************************//
ctr_error_t _stdcall CTR_SetPWM(uint32_t handle,ctr_nodeType_t node,int param,int pwmChannel, int16_t pulseWidth);
ctr_error_t _stdcall CTR_GetADC(uint32_t handle,ctr_nodeType_t node,int param,int channel, uint32_t * result);
ctr_error_t _stdcall CTR_GetPosition(uint32_t handle,ctr_nodeType_t node,int param,int channel, uint32_t * result);
ctr_error_t _stdcall CTR_GetVelocity(uint32_t handle,ctr_nodeType_t node,int param,int channel, uint32_t * result);
ctr_error_t _stdcall CTR_SetSolenoid(uint32_t handle,ctr_nodeType_t node,int param,int channel, bool enable);
ctr_error_t _stdcall CTR_SetRelay(uint32_t handle,ctr_nodeType_t node,int param,int channel, unsigned char state);
ctr_error_t _stdcall CTR_GetGPIO(uint32_t handle,ctr_nodeType_t node,int param, uint32_t * result);
//********************************* Raw CAN API *********************************//
#define CANFrame_Option_Extended_Frame	(1)
#define CANFrame_Option_Remote_Frame	(2)
#define CANFrame_Option_Base_Frame		(4)
#define CANFrame_Option_Transmitted		(8)
typedef struct _CANFrame_t
{
	uint32_t arbid;
	uint32_t dlc;
	uint32_t options;
	uint8_t data[8];
}CANFrame_t;

ctr_error_t _stdcall CTR_SetFilter(	uint32_t handle, 
unsigned int iFilterIdx,
const CANFrame_t * pMsgData,
const CANFrame_t * pMsgMask);

ctr_error_t _stdcall CTR_ClearFilter(	uint32_t handle, 
unsigned int iFilterIdx);

ctr_error_t _stdcall CTR_GetFrames(	uint32_t handle, 
CANFrame_t * frames,
uint32_t capacity,
uint32_t * num_msgs);

ctr_error_t _stdcall CTR_SendFrames(	uint32_t handle, 
	const CANFrame_t * frames,
	uint32_t num_msgs);

#endif // _2CAN_DLL_API__h_



